from PyQt6.QtWidgets import QApplication, QMainWindow, QAction, QToolBar, QLabel
import sys

class MyMainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        # 设置窗口标题和初始大小
        self.setWindowTitle('QMainWindow Example')
        self.setGeometry(100, 100, 600, 400)

        # 创建菜单栏
        menubar = self.menuBar()
        file_menu = menubar.addMenu('File')

        # 创建菜单项
        exit_action = QAction('Exit', self)
        exit_action.triggered.connect(self.close)
        file_menu.addAction(exit_action)

        # 创建工具栏
        toolbar = QToolBar('Main Toolbar')
        self.addToolBar(toolbar)

        # 创建工具栏按钮
        info_action = QAction('Show Info', self)
        info_action.triggered.connect(self.show_info)
        toolbar.addAction(info_action)

        # 设置中心窗口
        central_widget = QLabel('This is the central widget')
        self.setCentralWidget(central_widget)

        # 创建状态栏
        self.statusBar().showMessage('Ready')

    def show_info(self):
        self.statusBar().showMessage('Info message displayed')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_window = MyMainWindow()
    main_window.show()
    sys.exit(app.exec_())